﻿<Window x:Class="AspNetMembershipManager.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:vm="clr-namespace:AspNetMembershipManager" mc:Ignorable="d"
        Title="MainWindow" Height="480" Width="958"
		d:DataContext="{d:DesignInstance vm:MainWindowViewModel}">
    <Grid>
		<Grid.Resources>
			<vm:BoolToStringConverter x:Key="BooleanToYesNo" FalseValue="No" TrueValue="Yes" />
		</Grid.Resources>
		<DockPanel>
			<TabControl Margin="12">
				<TabItem Header="Users">
					<Grid>
						<DataGrid ItemsSource="{Binding Users}" IsReadOnly="True" Margin="6,37,6,6" SelectedItem="{Binding Path=SelectedUser}" SelectionMode="Single" AutoGenerateColumns="False">
							<DataGrid.RowStyle>
								<Style TargetType="{x:Type DataGridRow}">
									<EventSetter Event="MouseDoubleClick" Handler="UserRowDoubleClick"/>
								</Style>
							</DataGrid.RowStyle>
							<DataGrid.ContextMenu>
								<ContextMenu>
									<MenuItem Command="ApplicationCommands.New" Header="New user"/>
									<Separator />
									<MenuItem Command="vm:MainWindowCommands.ResetPassword" Header="Reset password"/>
									<MenuItem Header="Activate user"
											  CommandParameter="{Binding SelectedUser}"
											  Command="{Binding SelectedUser.ActivateUserCommand}" />
									<MenuItem Header="Deactivate user"
									          CommandParameter="{Binding SelectedUser}"
									          Command="{Binding SelectedUser.DeactivateUserCommand}" />
									<MenuItem Header="Unlock user"
											  CommandParameter="{Binding SelectedUser}"
											  Command="{Binding SelectedUser.UnlockUserCommand}" />
									<Separator />
									<MenuItem Command="ApplicationCommands.Delete" Header="Delete user"/>
								</ContextMenu>
							</DataGrid.ContextMenu>
							<DataGrid.CommandBindings>
								<CommandBinding Command="ApplicationCommands.New" Executed="CreateUserExecuted" />
								<CommandBinding Command="vm:MainWindowCommands.ResetPassword" CanExecute="CanResetPassword" Executed="ResetPasswordExecuted" />
								<CommandBinding Command="ApplicationCommands.Delete" Executed="DeleteUserExecuted" />
							</DataGrid.CommandBindings>
							<DataGrid.Columns>
								<DataGridTextColumn Header="Username" Binding="{Binding UserName}" />
								<DataGridTextColumn Header="Email address" Binding="{Binding EmailAddress}" Width="*" />
								<DataGridTextColumn Header="Activated" Binding="{Binding IsAccountActivated, Converter={StaticResource BooleanToYesNo}}">
									<DataGridTextColumn.ElementStyle>
										<Style TargetType="{x:Type TextBlock}">
											<Style.Triggers>
												<Trigger Property="Text" Value="Yes">
													<Setter Property="Foreground" Value="DarkGreen"/>
												</Trigger>
												<Trigger Property="Text" Value="No">
													<Setter Property="Foreground" Value="Red"/>
												</Trigger>
											</Style.Triggers>
										</Style>
									</DataGridTextColumn.ElementStyle>
								</DataGridTextColumn>
								<DataGridTextColumn Header="Locked out" Binding="{Binding IsAccountLocked, Converter={StaticResource BooleanToYesNo}}">
									<DataGridTextColumn.ElementStyle>
										<Style TargetType="{x:Type TextBlock}">
											<Style.Triggers>
												<Trigger Property="Text" Value="No">
													<Setter Property="Foreground" Value="DarkGreen"/>
												</Trigger>
												<Trigger Property="Text" Value="Yes">
													<Setter Property="Foreground" Value="Red"/>
												</Trigger>
											</Style.Triggers>
										</Style>
									</DataGridTextColumn.ElementStyle>
								</DataGridTextColumn>
								<DataGridTextColumn Header="Date created" Binding="{Binding CreationDate}" />
								<DataGridTextColumn Header="Last login date" Binding="{Binding LastLoginDate}" />
                            </DataGrid.Columns>
						</DataGrid>
						<Button Content="Create new user" Height="23" HorizontalAlignment="Right" Margin="0,6,6,0" VerticalAlignment="Top" Width="114" Click="CreateUserExecuted" />
					</Grid>
				</TabItem>
				<TabItem Header="Roles" IsEnabled="{Binding RolesEnabled}">
                    <TabItem.Style>
                        <Style TargetType="{x:Type TabItem}">
                            <Style.Triggers>
                                <Trigger Property="IsEnabled" Value="False">
                                    <Setter Property="ToolTip" Value="Membership roles are not enabled"/>
                                    <Setter Property="ToolTipService.ShowOnDisabled" Value="True"/>
                                </Trigger>
                            </Style.Triggers>
                        </Style>
                    </TabItem.Style>
					<Grid>
						<Button Content="Create new role" Height="23" HorizontalAlignment="Right" Margin="0,6,6,0" VerticalAlignment="Top" Width="114" Click="CreateRoleExecuted" />
						<DataGrid ItemsSource="{Binding Roles}" IsReadOnly="True" Margin="6,37,6,6" SelectedItem="{Binding Path=SelectedRole}" SelectionMode="Single">
							<DataGrid.ContextMenu>
								<ContextMenu>
									<MenuItem Command="ApplicationCommands.New" Header="New role"/>
									<Separator />
									<MenuItem Command="ApplicationCommands.Delete" Header="Delete role"/>
								</ContextMenu>
							</DataGrid.ContextMenu>
							<DataGrid.CommandBindings>
								<CommandBinding Command="ApplicationCommands.New" Executed="CreateRoleExecuted" />
								<CommandBinding Command="ApplicationCommands.Delete" Executed="DeleteRoleExecuted" />
							</DataGrid.CommandBindings>
							<DataGrid.Columns>
								<DataGridTextColumn Header="Role name" Binding="{Binding Name}" />
								<DataGridTextColumn Header="Number of users" Binding="{Binding UsersInRole}" Width="*" />
							</DataGrid.Columns>
						</DataGrid>
					</Grid>
				</TabItem>
			</TabControl>
		</DockPanel>
	</Grid>
</Window>
